﻿using System;
using System.Web.Mvc;
using PartyInvites.Models;

namespace PartyInvites.Controllers
{
    public class HomeController : Controller
    {
        public ViewResult Index()
        {
            int hour = DateTime.Now.Hour;
            ViewData["greeting"] = (hour < 12) ? "Good morning" : "Good afternoon";
            return View();
        }

        [HttpGet]
        public ViewResult RsvpForm()
        {
            return View();
        }

        // model binding !
        // incoming data is automatically parsed and used 
        // to populate action method parameters by matching incoming key/value pairs with the names of properties on the desired .NET type

        // DataAnnotations: validate incoming data when it performs model binding

        [HttpPost]
        public ViewResult RsvpForm(GuestResponse guestResponse)
        {
            if (ModelState.IsValid) {
                guestResponse.Submit();
                return View("Thanks", guestResponse);
            }
            else // Validation error, so redisplay data entry form
                return View();
        }
    }
}
